package demo3;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-08-02
 * Time: 10:33
 */
public class Test2 {
    public static Object object = new Object();
    public static int sum1 = 0;
    public static void main(String[] args) throws InterruptedException {
//        Thread t = new Thread(() -> {
//                try {
//                    Thread.sleep(5000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//
//        });
//
//        System.out.println(t.getState());
//        t.start();
//        System.out.println(t.getState());
//        Thread.sleep(1000);
//        System.out.println(t.getState());
        //t.wait();
//        Thread t = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("1");
//            }
//        });
//        t.start();
//        System.out.println("2");


        Random random = new Random();
        int[] ints = new int[10000000];
        for (int i = 0; i < ints.length; i++) {
            ints[i] = random.nextInt(100) + 1;
        }

        AtomicInteger sum2 = new AtomicInteger();
        Thread t1 = new Thread(() -> {
            for (int i = 1; i < ints.length; i += 2) {
                sum1 += ints[i];
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < ints.length; i+=2) {
                sum2.addAndGet(ints[i]);
            }
        });

    }
}
